package com.ocean.array;

public class WaterContainer3 {

    public static void main(String[] args) {
        int[] height = new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7};
//        int[] height = new int[]{1, 1};
        System.out.println(new WaterContainer3().maxArea(height));
    }


    public int maxArea(int[] height) {
        if (height.length <= 1) {
            return 0;
        }
        int pre = 0;
        int last = height.length - 1;
        int max = 0;
        while (pre < last) {
            int min = Math.min(height[pre], height[last]);
            int area = (last - pre) * min;
            max = Math.max(max, area);
            // 快速跳过
            while (pre < last && height[pre] <= min) {
                pre++;
            }
            while (pre < last && height[last] <= min) {
                last--;
            }
        }
        return max;
    }

}
